package com.yunzhong.appointment.listAnnouncement.controller;

import com.github.pagehelper.PageInfo;
import com.yunzhong.appointment.entity.Noticeboard;
import com.yunzhong.appointment.listAnnouncement.service.IListAnnouncementService;
import com.yunzhong.appointment.util.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 何文博
 * 最新公告
 */
@Controller
public class listAnnouncementController {
    @Autowired
    private IListAnnouncementService listAnnouncementService;

    /**
     * 查询
     * @param model
     * @return
     */
    @RequestMapping("/listAnnouncement/query")
    public  String query(ModelMap model, HttpServletRequest request){
        PageData pd = new PageData(request);
       List<Noticeboard> List=listAnnouncementService.queryAll(pd);
        model.addAttribute("List",List);
        PageInfo page =new PageInfo(List);
        model.addAttribute("page",page);

        return "listAnnouncement/listAnnouncement";
    }

    /**
     * 查一条
     * @param id
     * @param model
     * @return
     */
    @RequestMapping("/pageAnnouncement/queryById")
    public  String queryById(String id,ModelMap model){
        Noticeboard notice=listAnnouncementService.queryById(id);
        model.addAttribute("notice",notice);


        return "listAnnouncement/pageAnnouncement";
    }
}
